home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacHack 1998
/
MacHack 1998.toast
/
The Hacks!
/
jobs ƒ
/
jobs.c
< prev
next >
Wrap
C/C++ Source or Header
|
1998-06-21
|
5KB
|
164 lines
/****************************************************************************************
jobs.cp
Copyright © 1998 Red Shed Software. All rights reserved.
by Jonathan 'Wolf' Rentzsch (jon@redshed.net)
You'll need the dcmdGlue.a.o object file and Dcmd.h header file to compile this code.
You can find it on the Developer Series Tool Chest CD in the MacsBug folder or maybe
on the web.
Commenter Date Comment
--------- ----------------- -----------------------------------------------------
wolf Fri, Jun 19, 1998 Created ( at 2:55:24 AM at MacHack 13 ).
************************************************************************************/
#include "Dcmd.h"
#include "A4Stuff.h"
#include "LowMem.h"
/* Here's the undocumented Progress Manager call that's key to our dcmd */
extern pascal OSErr
KillProcess( const ProcessSerialNumber *PSN ) = { 0x3F3C,
0x0044,
0xA88F };
/**************************
*
* Funky Protos
*
**************************/
void dcmdHandleHelp();
void dcmdHandleGetInfo( dcmdBlock *paramPtr );
void dcmdHandleDoIt();
/****************************************************************************************
Commenter Date Comment
--------- ----------------- -----------------------------------------------------
wolf Tue, Aug 12, 1997 Created.
wolf Wed, Nov 5, 1997 Broke down monolithic main() into separate functions.
************************************************************************************/
pascal void
main( dcmdBlock *paramPtr )
{
long oldA4 = SetCurrentA4();
switch( paramPtr->request ) {
case dcmdHelp:
dcmdHandleHelp();
break;
case dcmdGetInfo:
dcmdHandleGetInfo( paramPtr );
break;
case dcmdDoIt:
dcmdHandleDoIt();
break;
default:
break;
}
SetA4(oldA4);
}
/****************************************************************************************
Commenter Date Comment
--------- ----------------- -----------------------------------------------------
wolf Sat, Jun 20, 1998 Created.
************************************************************************************/
void
dcmdHandleHelp()
{
dcmdDrawLine("\pKills every process except the Finder.");
}
/****************************************************************************************
Commenter Date Comment
--------- ----------------- -----------------------------------------------------
wolf Sat, Jun 20, 1998 Created.
************************************************************************************/
void
dcmdHandleGetInfo( dcmdBlock *paramPtr )
{
dcmdFillVersion( paramPtr, 0x03008000 );
dcmdFillString( paramPtr, usageStr, "\pnada (kills every process save the Finder)" );
dcmdFillString( paramPtr, creditsStr, "\pby Jonathan ‘Wolf’ Rentzsch (jon@redshed.net)" );
}
/****************************************************************************************
Commenter Date Comment
--------- ----------------- -----------------------------------------------------
wolf Sat, Jun 20, 1998 Created.
************************************************************************************/
void
dcmdHandleDoIt()
{
static Str255 kZombies[] = { "\pCopland",
"\pNewton",
"\pOpenDoc",
"\pRhapsody",
"\pTaligent",
"\pPowerTalk",
"\pQuickDraw GX",
"\pDylan" };
Str255 string, name = "\p";
ProcessSerialNumber psn = { kNoProcess, kNoProcess };
ProcessInfoRec info;
// Random() crashes at MacsBug time so we use the low
// three bits of TickCount() for our random index.
short r = ( TickCount() & 0x00000007 );
OSErr err = noErr;
info.processInfoLength = sizeof( info );
info.processName = name;
info.processAppSpec = nil;
if( !err ) {
err = GetCurrentProcess( &psn );
}
if( !err ) {
err = GetProcessInformation( &psn, &info );
}
if( !err && info.processSignature != 'MACS' ) {
dcmdDrawLine( "\pThe Finder has to be the current process in order not to crash MacsBug" );
return;
}
if( !err ) {
err = GetFrontProcess( &psn );
}
dcmdDrawLine( "\pWe must focus on the Mac OS to move forward.\nAll other processes are extraneous and must be killed." );
psn.highLongOfPSN = psn.highLongOfPSN = kNoProcess;
while( !err ) {
if( !err ) {
err = GetProcessInformation( &psn, &info );
}
if( !err && info.processSignature != 'MACS' ) {
err = KillProcess( &psn );
if( !err ) {
BlockMoveData( err ? "\pjobs: error #" : "\pkilled process “", string, 17 );
if( err ) NumToString( err, name );
BlockMoveData( name + 1, string + 1 + string[ 0 ], name[ 0 ] );
string[ 0 ] += name[ 0 ];
if( !err ) string[ ++string[ 0 ] ] = '”';
dcmdDrawLine( string );
}
}
if( !err )
err = GetNextProcess( &psn );
}
BlockMoveData( "\pkilled process “", string, 17 );
BlockMoveData( kZombies[ r ] + 1, string + 1 + string[ 0 ], kZombies[ r ][ 0 ] );
string[ 0 ] += kZombies[ r ][ 0 ];
string[ ++string[ 0 ] ] = '”';
dcmdDrawLine( string );
}